package com.example.myapplication.ui.activity.search

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.myapplication.request.CollectRequest
import com.example.myapplication.request.SearchRequest
import kotlinx.coroutines.launch

/**
 *搜索的viewModel
 *
 * @author : Kun
 * @date : 2021/6/9
 * @time : 15:19
 */
class SearchViewModel : ViewModel() {
    /**
     * 搜索的请求
     */
    val searchRequest = SearchRequest()
    /**
     * 收藏相关的request
     */
    val collectRequest = CollectRequest()

    /**
     * 请求搜索热词
     */
    fun requestHotKey(){
        viewModelScope.launch {
            searchRequest.requestHotKey()
        }
    }

    /**
     * 请求搜索结果
     * @param index 页码
     * @param k 关键词
     */
    fun requestSearchList(index: Int, k: String){
        viewModelScope.launch {
            searchRequest.requestSearchList(index,k)
        }
    }

    /**
     * 新增文章收藏
     */
    fun requestAddCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestAddCollectArticle(id)
        }
    }

    /**
     * 取消文章收藏
     */
    fun requestDelCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestDelCollectArticle(id)
        }
    }
}